package Acwing.基础算法;

import java.util.Scanner;

/**
 * @Title: prefixSum
 * @Author 贾金博
 * @Package Acwing.基础算法
 * @Date 2025/4/9 下午5:44
 * @description: 前缀和
 */
public class prefixSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] a = new int[n + 10];
        int[] sum = new int[n + 10];
        sum[0] = 0;

        for(int i = 1; i <= n; i ++ ) {
            a[i] = sc.nextInt();
            sum[i] = sum[i - 1] + a[i];
        }

        while(q-- > 0) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(sum[r] - sum[l - 1]);
        }
    }
}
